<template>
	<div>
		<div style="text-indent:2em;margin: 2% auto auto auto;width: 95%;">
			<div>
				回答详情: {{ answer }}
			</div>
		</div>
		<van-divider />
		<!-- 回复详情 -->
		<div>
			<div v-for="(item, index) in replys" :key="index" style="margin-left: 5%;">
				<div style="display: flex;">
					<div>
						{{ item.replyUsername }}:
					</div>
					
					<div style="margin-left: 2%;margin-top: -0.3%;">
						<van-button type="warning" size="mini" @click="reply_reply(item.replyId)">回复</van-button>
					</div>
				</div>
				<div style="text-indent:2em;margin-left: 2%;margin-top: 2%;" @longpress="delReply(item)"> 
					{{ item.replyMessage }}
				</div>
				<div style="padding-top: 5%;" v-if="item.replyMaterial !== 0">
					<van-button type="danger" size="small" @click="openReplyMaterial(item)">查看回复附件</van-button>
				</div>
				<div style="font-size: 13px;margin-left: 45%;margin-top: 6%;margin-bottom: 3%;">
					<div style="margin-right: 3px;">
						回复时间: {{ item.replyTime }}
					</div>
				</div>
				<van-divider />
				<!-- 回复回复 -->
				<div style="margin-left: 8%;font-size: 14px;" v-if="reply_replys[index].length > 0">
					<div v-for="(item1, index1) in reply_replys[index]" :key="index1">
						<div>
							{{ item1.replyUsername }}:
						</div>
						<div style="text-indent:2em;margin-left: 2%;margin-top: 2%;" @longpress="delReply(item1)">
							{{ item1.replyMessage }}
						</div>
						<div style="padding-top: 5%;" v-if="item1.replyMaterial !== 0">
							<van-button type="danger" size="small" @click="openReplyMaterial(item1)">查看回复附件</van-button>
						</div>
						<div style="font-size: 13px;margin-left: 45%;margin-top: 6%;margin-bottom: 2%;">
							<div style="margin-right: 3px;">
								回复时间: {{ item1.replyTime }}
							</div>
						</div>
						<van-divider />
					</div>
					
				</div>
				<van-divider />
			</div>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				answer_id: '',
				answer: '',
				replys: [],
				reply_replys: [[]]
			}
		},
		onLoad: function(option) {
			this.answer_id = option.answer_id;
			this.answer = option.answer;
			this.getMessage();
			console.log(this.answer_id);
			console.log(this.answer)
		},
		onShow(){
			this.getMessage();
		},
		created() {

		},
		methods: {
			getMessage(){
				uni.request({
					method: 'POST',
					url: 'https://www.gjegm.ltd/czsczq/answerReply/getReplyByAnswerid',
					data: {
						answer_id: this.answer_id
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'token': uni.getStorageSync('token')
					},
					success: (res) => {
						console.log(res)
						this.replys = res.data.obj;
						this.reply_replys = res.data.obj2
					}
				});
			},
			reply_reply(item){
				uni.navigateTo({
					url: '/pages/question/reply_reply?reply_id=' + item
				});
			},
			openReplyMaterial(item){
				console.log(item)
				uni.navigateTo({
					url: '/pages/question/reply_material?reply_id=' + item.replyId
				});
			},
			delReply(item1){
				const that = this;
				if (item1.replyUserid === uni.getStorageSync('userid')){
					uni.showModal({
					    title: '提示',
					    content: '是否删除回复',
					    success: function (res) {
					        if (res.confirm) {
					            uni.request({
					            	method: 'POST',
					            	url: 'https://www.gjegm.ltd/czsczq/answerReply/delReplyById',
					            	data: {
					            		id: item1.replyId
					            	},
					            	header: {
					            		'content-type': 'application/x-www-form-urlencoded',
					            		'token': uni.getStorageSync('token')
					            	},
					            	success: (res) => {
					            		if (res.data.obj) {
					            			
					            			uni.showToast({
					            				title: '删除成功!',
					            				mask: true,
					            				icon: 'none'
					            			});
											that.getMessage();
					            		}
					            	}
					            });
					        } else if (res.cancel) {}
					    }
					});
				}else {
					uni.showToast({
						title: '您不可删除别人的回复!',
						mask: true,
						icon: 'none'
					})
				}
			},
		}
	}
</script>

<style>
</style>
